package com.cssl.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cssl.domain.DtsAd;
import com.cssl.domain.dto.DtsAdDto;
import com.cssl.domain.dto.DtsAddressDto;
import com.cssl.service.DtsAdService;
import com.cssl.service.DtsAddressService;
import com.cssl.util.InfoCode;
import com.cssl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/promotion")
public class DtsAdController {

    @Autowired
    private DtsAdService dtsAdService;

    @PostMapping("/listAd")
    public Result getlistAd(@RequestBody DtsAdDto dto) {
        Map dtsAdList = dtsAdService.getDtsAdList(dto);
        if (ObjectUtil.isEmpty(dtsAdList.get("list"))) {
            return Result.result(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, null, System.currentTimeMillis());
        }
        return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, dtsAdList, System.currentTimeMillis());

    }

    @PostMapping("/createAd")
    public Result createAd(@RequestBody DtsAd dto) {
        int ad = dtsAdService.createAd(dto);
        System.out.println("提供者:" + dto);
        if (ad > 0) {
            return Result.result(InfoCode.CREATED, InfoCode.MESSAGE_CREATED, dto, System.currentTimeMillis());

        } else {
            return Result.result(InfoCode.FAILED, InfoCode.MESSAGE_FAILED, null, System.currentTimeMillis());
        }


    }
}
